import logging
import time
from riff_wave.core import WaveContainer, riff_wave_logger

riff_wave_logger.setLevel(logging.DEBUG)

# 1. read and parse
time_start = time.perf_counter()
with open('samples/sil_2s_marker.wav', 'rb') as f:
    wave = WaveContainer.from_stream(f)
time_end = time.perf_counter()
print(f'[parse] time cost: {time_end - time_start:.3f}s')
print(f'{wave.fmt = }')
print(f'{wave.duration = }')

# 2. get adtl annotations
adtl_annotations = wave.get_adtl_annotations()
print(f'{adtl_annotations = }')

# 3. rewrite
# todo: create new adtl annotations and save to new .wav file.
time_start = time.perf_counter()
with open('samples/sil_2s_marker_rewrite.wav', 'wb') as f:
    f.write(wave.dump())
time_end = time.perf_counter()
print(f'[dump] time cost: {time_end - time_start:.3f}s')


